package com.danlu.mvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiImplicitParam;
import com.wordnik.swagger.annotations.ApiImplicitParams;
import com.wordnik.swagger.annotations.ApiOperation;

@Api(value = "/student", description = "学生管理")
@Controller
public class StudentController {


	@RequestMapping(value = "/student", method = RequestMethod.GET)
	public ModelAndView student() {
		return new ModelAndView("student", "command", new Student());
	}

	@RequestMapping(value = "/redirect", method = RequestMethod.GET)
	public String redirect(ModelMap model) {
		model.addAttribute("name", "Caroline");
		model.addAttribute("age", 22);
		model.addAttribute("id", "w34");
		return "redirect:student";
	}

	@RequestMapping(value = "/addStudent", method = RequestMethod.POST)
	public String addStudent(@ModelAttribute("SpringWeb") Student student, ModelMap model) {
		model.addAttribute("name", student.getName());
		model.addAttribute("age", student.getAge());
		model.addAttribute("id", student.getId());

		return "result";
	}
	@ApiOperation(value = "查找用户", notes = "根据用户ID查询用户详细信息", httpMethod = "GET")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "province",required = false, value = "省",paramType ="query", dataType = "String"),
		@ApiImplicitParam(name = "city",required = false, value = "市",paramType ="query", dataType = "String"),
		@ApiImplicitParam(name = "county",required = false, value = "县",paramType ="query", dataType = "String"),
        @ApiImplicitParam(name = "pageable",required = false, value = "分页，排序对象",paramType ="body", dataType = "Pageable")
	})
	@RequestMapping(value = "/getUserInfo", method = RequestMethod.GET)
	public ModelAndView addStudent(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView model = new ModelAndView("message");
		String info = null;
		if (request.getParameter("content") != null) {
			info = request.getParameter("content");
		}
		model.addObject("message", "user Info :" + info);
		return model;
	}
}